# 题目：输入一个链表的头节点，从尾到头反过来打印出每个节点的链表
# 可以考虑使用栈结构

from provate import *
import typing
import numpy as np


def print_list_reverse_1(head: listNode):
    # 使用栈
    # 实际上python中的列表也可以通过append和pop方法实现类似栈的功能
    res = []
    p_Node = head
    while p_Node is not None:
        res.append(p_Node.value)
        p_Node = p_Node.next

    while len(res) > 0:
        print(res.pop(), end=',')


def print_list_reverse_2(head:listNode):
    # 既然已经想到了栈，那就有栈结构的递归方法
    if head is not None:
        if head.next is not None:
            print_list_reverse_2(head.next)
        print(head.value, end=' ')


if __name__ == '__main__':
    ls = list(np.random.randint(0, 20, 10))
    print(ls, type(ls))

    head = list2pList(ls)
    print_list_reverse_1(head)
    print()
    print_list_reverse_2(head)